package com.example.demodatadruid.controller;

import com.example.demodatadruid.Entity.Department;
import com.example.demodatadruid.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/departments")
public class DepartmentController {
    @Autowired(required = false)
    DepartmentService departmentService;

    @GetMapping("/")
    public List<Department> getAllDepartments(){
        return departmentService.getAllDepartments();
    }

    @GetMapping("/{id}")
    public Department getDepartmentById(@PathVariable Integer id){return departmentService.getDepartmentById(id);}

    @PostMapping("/")
    public Integer addDepartment(@RequestBody Department department){
        return departmentService.addDepartment(department);
    }
    @PutMapping("/")
    public Integer updateDepartment(@RequestBody Department department){return departmentService.updateDepartment(department);}

    @DeleteMapping("/{id}")
    public Integer deleteDepartmentById(@PathVariable Integer id){return departmentService.deleteDepartment(id);}

}

